<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
<div id="app">
    <input type="button" value="启动" @click="lang">
    <input type="button" value="停止" @click="stopLang">
    <hr>
    <h1 v-text="msg"></h1>
</div>
<script src="vue.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            msg: '猥琐发育，别浪！！',
            timerId: null
        },
        methods: {
            lang: function () {
                var that = this;
                console.log(this);
                clearInterval(that.timerId);
                that.timerId = setInterval(function () {
                    console.log(this);
                    var first = that.msg.substr(0, 1);
                    var last = that.msg.substr(1);
                    that.msg = last + first;
                }, 200)
                //自定义指向外部的this，则可不用声明that
//                    this.msg =this.msg.substr(1) + this.msg.substr(0, 1)
//                }.bind(this), 200)
            },
            stopLang: function () {
                clearInterval(this.timerId)
            }
        }
    })
</script>
</body>

</html>